﻿using Hotel.DAL;
using Hotel.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Hotel.BLL
{
    public class ShopBLL
    {
        public ShopBLL(ShopDAL shopDAL) 
        {
            ShopDAL = shopDAL;
        }

        public ShopDAL ShopDAL { get; }


        /// <summary>
        /// 增加门店
        /// </summary>
        /// <param name="shop"></param>
        /// <returns></returns>
        public int ShopAdd(Shop shop)
        {
            try
            {
                int res = ShopDAL.SearchShopName(shop.Name);
                if (res > 0)
                {
                    return -1;
                }
                else
                {
                    int r = ShopDAL.ShopAdd(shop);
                    if (r>0)
                    {
                        return 1;//增加成功
                    }
                    else
                    {
                        return -2;//增加失败
                    }
                }
            }
            catch (Exception)
            {

                throw;
            }
        }


        /// <summary>
        /// 分页显示
        /// </summary>
        /// <param name="totalCount"></param>
        /// <param name="totalPage"></param>
        /// <param name="name"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public List<Shop> GetShops(out int totalCount, out int totalPage, string? name, int pageIndex, int pageSize)
        {
            try
            {
                List<Shop> list = ShopDAL.GetShops(out totalCount,out totalPage, name, pageIndex, pageSize);

                return list;
            }
            catch (Exception)
            {

                throw;
            }
        }


        /// <summary>
        /// 逻辑删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int DelShop(int id)
        {
            try
            {
                var res = ShopDAL.DelShop(id);
                return res;
            }
            catch (Exception)
            {

                throw;
            }
        }


        /// <summary>
        /// 门店信息反填
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Shop FanShop(int id)
        {
            try
            {
                return ShopDAL.FanShop(id);
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 门店修改
        /// </summary>
        /// <param name="shop"></param>
        /// <returns></returns>
        public int UpdShop(Shop shop)
        {
            try
            {
                var res = ShopDAL.UpdShop(shop);
                return res;
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
